import { BasicDrawer, useDrawerInner } from "@/components/Drawer";
import "./index.less";
import { useState } from "react";
import { listTreatmentsDept } from "@/api/SecondmentDictionary";
import { useTranslation } from "react-i18next";
import { drugBatchApi } from "@/api/MedicalExamination/recipe";
import { message } from "antd";
import { BasicProTable, useProTable } from "@/components/ViewComponents/proTable";
const TreatmentPhmList = (props: { register: Fn; success?: Fn }) => {
	const { t } = useTranslation();
	const defaultColumns = [
		{
			title: t("MedicalExamination.recipe.treatmentPlan"),
			dataIndex: "trtmtName"
		},
		{
			title: t("MedicalExamination.recipe.treatmentContent"),
			dataIndex: "trtmtContent"
		},
		{
			title: t("MedicalExamination.recipe.patient"),
			dataIndex: "patientId"
		},
		{
			title: t("MedicalExamination.recipe.doctor"),
			dataIndex: "doctorId"
		}
	];
	const [trtmtId, setTrtmtId] = useState("");
	const [registerDrawer, { closeDrawer }] = useDrawerInner(props.register, data => {
		setTrtmtId(data.trtmtId);
	});
	const [register, { submit }] = useProTable({
		api: listTreatmentsDept,
		defaultColumns,
		key: "planId",
		type: "Checkbox",
		parameter: {
			trtmtId
		}
	});
	const handleSubmit = async () => {
		const phmSaveList = await submit();
		if (!phmSaveList) return;
		const res = await drugBatchApi.drugRequestsApply({ trtmtId, phmSaveList });
		if (!res) message.error(t("kevin_ui.addFailed"));
		message.success(t("kevin_ui.addedSuccessfully"));
		closeDrawer();
	};

	return (
		<div>
			<BasicDrawer showFooter={true} size="large" {...props} register={registerDrawer} ok={handleSubmit}>
				<div className="recipe">
					<BasicProTable register={register}></BasicProTable>
				</div>
			</BasicDrawer>
		</div>
	);
};

export default TreatmentPhmList;
